﻿using System;
using Core.Library;
using DataObject;
using DataObject.Article;

public partial class Controls_Common_Static : System.Web.UI.UserControl
{
    protected int Id;
    protected int TypeId;
    
    protected string Title          = string.Empty;
    protected string Body           = string.Empty;
    protected string Source         = string.Empty;
    protected string CategoryName   = string.Empty;

    protected void Page_Load(object sender, EventArgs e)
    {
        Id      = Utils.GetIdFromRequestString(Utils.Id, 0);
        TypeId  = Utils.GetIdFromRequestString(Utils.TypeId, 0);

        if (TypeId > 0 && Id > 0)
        {
            switch (TypeId)
            {
                case (int)StaticType.Category:
                    GetArticleByCategory();
                    break;
                case (int)StaticType.Article:
                    GetArticleDetail();
                    break;
            }            
        }
    }

    private void GetArticleByCategory()
    {
        try
        {
            var o = ArticleController.Article_GetListByCategoryId(Id);
            if (o != null)
            {
                Title = o[0].Title;
                Body = o[0].Body;
            }
        }
        catch
        {
            ltMessage.Text = MessageUtility.ShowMessage(string.Empty, "Không có bài viết nào. Vui lòng quay lại sau.", MessageType.Information);
        }
        
    }

    public void GetArticleDetail()
    {
        try
        {
            var o = ArticleController.Article_GetById(Id);
            if (o != null)
            {
                Title = o.Title;
                Body = o.Body;
            }
        }
        catch
        {
            ltMessage.Text = MessageUtility.ShowMessage(string.Empty, "Không có bài viết nào. Vui lòng quay lại sau.", MessageType.Information);
        }
    }
}